package com.keke.myblogv1.config;


import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Object handlerException(Exception e) {
        String msg = e.getMessage();
        if (msg == null || msg.equals("")) {
            msg = "服务器出错,请联系开发人员";
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("message",msg);
        if("token 无效，请重新获取".equals(msg)){
            jsonObject.put("code",50008);
        }
        return jsonObject;
    }
}
